<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="../css/byking.css">
<link rel="stylesheet" href="../layui/css/layui.css">

</head>
<body>
	<div class="byking-form" id="modifysysuserinfo">
		<form class="layui-form" action="" >
			<div class="layui-form-item">
				<label class="layui-form-label">姓名</label>
				<div class="layui-input-inline">
					<input type="text" name="name" required lay-verify="name"  value="{{user.name}}"
						placeholder="请输入标题" autocomplete="off" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">手机号码</label>
				<div class="layui-input-inline">
					<input type="text" name="phone" required lay-verify="phone"  value="{{user.phone}}"
						placeholder="请输入标题" autocomplete="off" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">性别</label>
				<div class="layui-input-block">
					<input type="radio" name="sex" value="1" title="男" :checked="user.sex==1"> 
					<input type="radio" name="sex" value="0" title="女" autocomplete="off" :checked="user.sex==0">
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>

	<!-- jQuery -->
	<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
	<!-- jquery.cookie -->
	<script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	<!-- layer -->
	<script src="https://cdn.bootcss.com/layer/3.0.1/layer.min.js"></script>
	<!-- vue -->
	<script src="http://cdn.jsdelivr.net/vue/1.0.7/vue.min.js"></script>
	<script src="../layui/layui.js"></script>
	<script src="../js/byking.js"></script>
	<script src="../js/byking-verify.js"></script>
	<script src="../js/hostconfig.js"></script>

	<script>
		
    	var modifysysuserinfo = new Vue({
	        el: "#modifysysuserinfo",
	        data: {
	        	user: null
	        }
	    });
		
		function getUserInfo() {
			var userId = $byking.getUrlParam("userId");
			var url = $hostconfig.sysAuthHost+"/user/info?guid="+userId;
			$byking.getJSONWithToken(url,function(data){
				modifysysuserinfo.user = data.data;
				setTimeout(function () { 
					var form = layui.form();
					form.render("radio");
			    }, 100);
			});
		}
		
		getUserInfo();
		
		//提交
		layui.use('form', function() {
			var form = layui.form();
			
			//验证提交
			form.verify({  
				name: function(value) {
	  				if(value.length == 0){  
						return '姓名必须填写';
					}
					if(value.length > 10){  
						return '姓名至多得10个字符';
					}
					if(!$bykingVerify.checkRule1(value)) {
						return '名字只能包括中文、英文、数字包括下划线';
					}
				}
			});

			//监听提交
			form.on('submit(formDemo)', function(data) {
				var user = modifysysuserinfo.user;
				var data = data.field;
				var newData = {
						guid: user.guid,
						name: data.name,
						sex: data.sex,
						phone: data.phone,
						update_by:$byking.getUrlParam("userId")
					};
					$byking.postJSONWithToken($hostconfig.sysAuthHost+"/user/update",newData,function(data){
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
					},function(data) {
	    				layer.msg(data.responseJSON.message);
	    			});
					return false;
			});
		});
	</script>
</body>
</html>